home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / misc / zxam16b.lha / ZXAM Spectrum / zxam_rexx / English / LoadFile.zxam < prev    next >
Encoding:
Text File  |  1994-10-23  |  3.7 KB  |  111 lines

  1. /* this script load a snapshot from disk */
  2. /* Uses the internal loaders of emulator (MIRAGE & PC) */
  3.  
  4.     address command
  5.  
  6.     if ~show(ports,ZXAM_REXX) then do
  7.         requestchoice 'title "ZXAM Script error..." body "I can''t find the emulator''s port!!" gadgets "AARGH!"'
  8.         exit
  9.         end
  10.  
  11. /* We use the emulator's filerequester */
  12.     
  13.     /* old window status */
  14.     oldname=zxamactname()
  15.     oldformat=zxamactformat()
  16.     
  17.     nombre=zxamloadrequester('Select a snapshot...')
  18.     if nombre='' then exit    /* CANCEL */
  19.     
  20.     bloque=zxampploadfile(nombre)    /* load the whole file */
  21.     
  22.     formato=zxamparseloaded(bloque)        /* parse the file if known format */
  23.     
  24.     if formato~='' then do            /* known format */
  25.         zxamnameformat(zxamfilepart(nombre),formato)
  26.         exit
  27.         end
  28.     
  29. /* Yep! Unknown format. Here you can put the relevant code for loading of */
  30. /* other formats */
  31.  
  32. /* This is an example of how to implement a format (mirage, in this case) */
  33.     if length(bloque)=49179 then do        /* MIRAGE (I think...) */
  34.         zxamsetreg(i,c2d(substr(bloque,1,1)))    /* register i */
  35.         zxamsetreg(lh2,c2d(substr(bloque,2,2)))    /* register hl' */
  36.         zxamsetreg(ed2,c2d(substr(bloque,4,2)))    /* register de' */
  37.         zxamsetreg(cb2,c2d(substr(bloque,6,2)))    /* register bc' */
  38.         zxamsetreg(f2,c2d(substr(bloque,8,1)))    /* register f' */
  39.         zxamsetreg(a2,c2d(substr(bloque,9,1)))    /* register a' */
  40.         zxamsetreg(lh,c2d(substr(bloque,10,2)))    /* register hl */
  41.         zxamsetreg(ed,c2d(substr(bloque,12,2)))    /* register de */
  42.         zxamsetreg(cb,c2d(substr(bloque,14,2)))    /* register bc */
  43.         zxamsetreg(yi,c2d(substr(bloque,16,2)))    /* register iy */
  44.         zxamsetreg(xi,c2d(substr(bloque,18,2)))    /* register ix */
  45.         zxamsetreg(int,bittst(substr(bloque,20,1),2)) /* interrupt status */
  46.         zxamsetreg(r,c2d(substr(bloque,21,1)))    /* register r */
  47.         zxamsetreg(f,c2d(substr(bloque,22,1)))    /* register f */
  48.         zxamsetreg(a,c2d(substr(bloque,23,1)))    /* register a */
  49.         zxamsetreg(ps,c2d(substr(bloque,24,2)))    /* register sp */
  50.         zxamsetreg(pc,zxamfindbyte(0,201))    /* address of a RET in ROM */
  51.         zxamsetreg(im,c2d(substr(bloque,26,1)))    /* interrupt mode */
  52.         zxamsetreg(bor,c2d(substr(bloque,27,1)))    /* border color */
  53.         /* put the 48k of RAM */
  54.         zxamputmem(16384,substr(bloque,28,49152))
  55.         
  56.         /* put name a formt in the window */
  57.         zxamnameformat(zxamfilepart(nombre),'mirage')
  58.         zxamnoreload()
  59.         
  60.         exit
  61.         
  62.         end
  63.  
  64.  
  65. /* this examle loads a PC snapshot */
  66.     if length(bloque)=49190 then do        /* format PC?? */
  67.         if left(bloque,2)~='SP' then break    /* same size, but no ID */
  68.         zxamsetreg(cb,c2d(substr(bloque,7,2)))
  69.         zxamsetreg(ed,c2d(substr(bloque,9,2)))
  70.         zxamsetreg(lh,c2d(substr(bloque,11,2)))
  71.         zxamsetreg(f,c2d(substr(bloque,13,1)))
  72.         zxamsetreg(a,c2d(substr(bloque,14,1)))
  73.         zxamsetreg(xi,c2d(substr(bloque,15,2)))
  74.         zxamsetreg(yi,c2d(substr(bloque,17,2)))
  75.         zxamsetreg(cb2,c2d(substr(bloque,19,2)))
  76.         zxamsetreg(ed2,c2d(substr(bloque,21,2)))
  77.         zxamsetreg(lh2,c2d(substr(bloque,23,2)))
  78.         zxamsetreg(f2,c2d(substr(bloque,25,1)))
  79.         zxamsetreg(a2,c2d(substr(bloque,26,1)))
  80.         zxamsetreg(r,c2d(substr(bloque,27,1)))
  81.         zxamsetreg(i,c2d(substr(bloque,28,1)))
  82.         zxamsetreg(ps,c2d(substr(bloque,29,2)))
  83.         zxamsetreg(cp,c2d(substr(bloque,31,2)))
  84.         zxamsetreg(bor,c2d(substr(bloque,35,1)))
  85.         zxamsetreg(int,bittst(substr(bloque,37,1),0))
  86.         zxamsetreg(im,1+bittst(substr(bloque,37,1),1))
  87.         /* put the 48k of RAM */
  88.         zxamputmem(16384,substr(bloque,39,49152))
  89.         
  90.         /* put new name and format */
  91.         zxamnameformat(zxamfilepart(nombre),'PC')
  92.         zxamnoreload()
  93.         
  94.         exit
  95.         
  96.         end
  97.  
  98.  
  99. /* if program reached this point means that the format is totally unknown */
  100. /* load error! */
  101.     
  102.     requestchoice 'title "ZXAM Script error..." body "Unknown format!!" gadgets "AARGH!"'
  103.  
  104.     if oldname='' then
  105.         zxamclearnameformat()
  106.     else
  107.         zxamnameformat(oldname,oldformat)
  108.  
  109.  
  110.     exit
  111.